
import 'package:easy_refresh/easy_refresh.dart';
import 'package:enterprise_v6_app/app/core/constans/storage.dart';
import 'package:enterprise_v6_app/app/core/http/http.dart';
import 'package:enterprise_v6_app/app/core/utils/network.dart';
import 'package:enterprise_v6_app/app/core/utils/storage_util.dart';
import 'package:enterprise_v6_app/app/core/utils/user_manager.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

import 'package:package_info_plus/package_info_plus.dart';


/// 全局静态数据
class Global {
  /// 是否第一次打开
  static bool isFirstOpen = false;

  /// 是否 release
  static bool get isRelease => const bool.fromEnvironment('dart.vm.product');

  /// app 相关信息
  static PackageInfo packageInfo = PackageInfo(
    appName: 'Unknown',
    packageName: 'Unknown',
    version: 'Unknown',
    buildNumber: 'Unknown',
    buildSignature: 'Unknown',
  );

  static initEasyRefresh() {
    // 全局设置
    EasyRefresh.defaultHeaderBuilder = () => const ClassicHeader(
        dragText: '下拉刷新',
        armedText: '释放刷新',
        readyText: '刷新中...',
        processingText: '刷新中...',
        processedText: '刷新完成',
        noMoreText: '没有更多',
        failedText: '刷新失败',
        messageText: '更新时间 %T');
    EasyRefresh.defaultFooterBuilder = () => const ClassicFooter(
        dragText: '上拉加载',
        armedText: '释放加载',
        readyText: '加载中...',
        processingText: '加载中...',
        processedText: '加载完成',
        noMoreText: '没有更多',
        failedText: '加载失败',
        messageText: '加载时间 %T');
  }

  /// init
  static Future init() async {
    // 运行初始
    WidgetsFlutterBinding.ensureInitialized();

    PackageInfo.fromPlatform().then((value) => packageInfo = value);

    // DeviceUtil.init();

    await StorageUtil.init();
    // await AppLocaleUtil.init();
    NetworkUtil.init();
    UserManager.init();
    // HttpProxyUtil.init();
    HttpUtil();
    // 读取设备第一次打开
    isFirstOpen = StorageUtil.getBool(StorageConstants.firstOpen) ?? true;
    StorageUtil.setBool(StorageConstants.firstOpen, false);

    // android 状态栏为透明的沉浸
    if (GetPlatform.isAndroid) {
      const systemUiOverlayStyle =
      SystemUiOverlayStyle(statusBarColor: Colors.transparent);
      SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
    }

    initEasyRefresh(); //初始化刷新样式

    // 强制竖屏
    await SystemChrome.setPreferredOrientations(
        [DeviceOrientation.portraitUp]);



  }
}
